<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>Cool Book网上书店</title>
		<link rel="stylesheet" href="css/site.css" />
		<link rel="stylesheet" href="css/glyphicon.css" />
		<link rel="stylesheet" type="text/css" href="css/book.css"/>
		<style>
			#picture{
				float:left;
				width: 30%;
				padding-top:10px;
			}
			#details{
				float:right;
				width: 70%;
				padding-top:10px;
			}
		</style>
	</head>
	<body>
		<header></header>
		
		<section>
			<div id="error">
				<h3>操作错误！</h3>
			</div>
			<div id="success">
				<div id="picture">
					<img id="pictureurl">
				</div>
				<div id="details">
					<h2 id="title"></h2>
					<hr />
					<table>
						<tr>
							<td>所属类别：</td>
							<td><span id="category"></span></td>
						</tr>
						<tr>
							<td>出版社：</td>
							<td><span id="publisher"></span></td>
						</tr>
						<tr>
							<td>出版日期：</td>
							<td><span id="publishdate"></span></td>
						</tr>
						<tr>
							<td>作者：</td>
							<td><span id="authors"></span></td>
						</tr>
						<tr>
							<td>原价：</td>
							<td>￥<span id="listprice"></span></td>
						</tr>
						<tr>
							<td>优惠价：</td>
							<td>￥<span id="reducedprice"></span></td>
						</tr>
						<tr>
							<td>版次：</td>
							<td><span id="edition"></span></td>
						</tr>
						<tr>
							<td>页数：</td>
							<td><span id="pages"></span></td>
						</tr>
						<tr>
							<td>关键字：</td>
							<td><span id="keywords"></span></td>
						</tr>
						<tr>
							<td>简介：</td>
							<td><span id="description"></span></td>
						</tr>
						<tr>
							<td></td>
							<td>
								<button class="btn green" id="buy">放入购物车</button>
							</td>
						</tr>
					</table>
				</div>
				<div class="clearfix"></div>
			</div>
		</section>
		
		<footer></footer>
		
		<script src="js/msgbox.js"></script>
		<script src="js/cookie.js"></script>
		<script src="js/cart.js"></script>
		<script type="text/javascript" src="js/util.js" ></script>
		<script type="text/javascript" src="js/pageInit.js" ></script>
		<script>
			var id = location.search.substr(location.search.indexOf('=') + 1);
			var url = 'dataservice/book' + id + ".js";
			getResource(url, function(result, data){
				var success = document.getElementById("success");
				var book = JSON.parse(data);
				if(result){
					document.getElementById("error").style.display = "none";
					
					document.getElementById("pictureurl").src = 
						"img/bookimages/" + (book.pictureurl?book.pictureurl:"nopicture.png");
					document.getElementById("title").innerHTML = book.title;
					document.getElementById("category").innerHTML = book.category;
					document.getElementById("publisher").innerHTML = book.publisher;
					document.getElementById("publishdate").innerHTML = book.publishdate;
					
					var authorStr = "";
					for (var j = 0; j < book.authors.length; j++) {
						var author = book.authors[j];
						if (author.country) {
							authorStr += "(" + author.country + ")";
						}
						authorStr += author.name + "&nbsp;&nbsp;"
					}
					document.getElementById("authors").innerHTML = authorStr;
					
					document.getElementById("listprice").innerHTML = book.listprice;
					document.getElementById("reducedprice").innerHTML = book.reducedprice;
					document.getElementById("edition").innerHTML = book.edition;
					document.getElementById("pages").innerHTML = book.pages;
					document.getElementById("description").innerHTML = book.description;
					
					var keywordStr = "";
					for(var j=0;j<book.keywords.length;j++){
						var keyword = book.keywords[j];
						keywordStr += keyword + "&nbsp;&nbsp;"
					}
					document.getElementById("keywords").innerHTML = keywordStr;
					
					var func = "cart.addToCart(" + book.id + ",'" + book.title + "'," + 
						book.reducedprice + ");updateCartSummary();";
					document.getElementById("buy").setAttribute("onclick", func);
				} else{
					success.style.display = "none";
				}
			});
		</script>
	</body>
</html>
